home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Run & Stumpy / source / aevent.cp < prev    next >
Encoding:
Text File  |  1992-06-19  |  2.8 KB  |  168 lines  |  [TEXT/MPS ]

  1. #define SystemSevenOrLater 1
  2.  
  3. #include <errors.h>
  4.  
  5. #include "aevent.h"
  6. #include "templock.h"
  7.  
  8. aevent::aevent( AEEventClass theclass,
  9.                      AEEventID id,
  10.                      const AEAddressDesc& target )
  11.   {
  12.     error= AECreateAppleEvent( theclass,
  13.                                         id,
  14.                                         &target,
  15.                                         kAutoGenerateReturnID,
  16.                                         kAnyTransactionID,
  17.                                         this );
  18.     mode= kAENoReply | kAECanInteract | kAECanSwitchLayer;
  19.     priority= kAENormalPriority;
  20.     timeout= kAEDefaultTimeout;
  21.     idler= 0;
  22.     filter= 0;
  23.   }
  24.  
  25. OSErr aevent::send()
  26.   {
  27.     if (iswrong())
  28.         return whatiswrong();
  29.     
  30.     return AESend( this,
  31.                         &reply,
  32.                         mode,
  33.                         priority,
  34.                         timeout,
  35.                         idler,
  36.                         filter );
  37.   }
  38.  
  39. void aevent::putparam( AEKeyword key,
  40.                               DescType type,
  41.                               void *data,
  42.                               uint32 size )
  43.   {
  44.     if (iswrong())
  45.         return;
  46.     
  47.     error= AEPutParamPtr( this,
  48.                                  key,
  49.                                  type,
  50.                                  (Ptr)data,
  51.                                  size );
  52.   }
  53.  
  54. void aevent::putparam( AEKeyword key,
  55.                               DescType type,
  56.                               Handle h )
  57.   {
  58.     if (iswrong())
  59.         return;
  60.     
  61.     templock lock(h);
  62.     
  63.     putparam( key, type, *h, GetHandleSize(h) );
  64.   }
  65.  
  66. void aevent::putparam( AEKeyword key, const AEDesc& param )
  67.   {
  68.     if (iswrong())
  69.         return;
  70.     
  71.     error= AEPutParamDesc( this, key, ¶m );
  72.   }
  73.  
  74. void aevent::putattribute( AEKeyword key,
  75.                                     DescType type,
  76.                                     void *data,
  77.                                     uint32 size )
  78.   {
  79.     if (iswrong())
  80.         return;
  81.     
  82.     error= AEPutAttributePtr( this,
  83.                                       key,
  84.                                       type,
  85.                                       (Ptr)data,
  86.                                       size );
  87.   }
  88.  
  89. void aevent::putattribute( AEKeyword key,
  90.                                     DescType type,
  91.                                     Handle h )
  92.   {
  93.     if (iswrong())
  94.         return;
  95.     
  96.     templock lock(h);
  97.     
  98.     putattribute( key, type, *h, GetHandleSize(h) );
  99.   }
  100.  
  101. void aevent::putattribute( AEKeyword key, const AEDesc& param )
  102.   {
  103.     if (iswrong())
  104.         return;
  105.     
  106.     error= AEPutAttributeDesc( this, key, ¶m );
  107.   }
  108.         
  109. OSErr aevent::getparam( AEKeyword key,
  110.                                 DescType desired,
  111.                                 DescType& realtype,
  112.                                 void *data,
  113.                                 uint32 maxsize,
  114.                                 uint32& truesize )
  115.   {
  116.     if (iswrong())
  117.         return whatiswrong();
  118.     
  119.     return AEGetParamPtr( this,
  120.                                  key,
  121.                                  desired,
  122.                                  &realtype,
  123.                                  (Ptr)data,
  124.                                  maxsize,
  125.                                  (Size *)&truesize );
  126.   }
  127.  
  128. OSErr aevent::getparam( AEKeyword key,
  129.                                 DescType desired,
  130.                                 DescType& realtype,
  131.                                 Handle& result )
  132.   {
  133.     uint32 size;
  134.     OSErr error= getparam( key,
  135.                                   desired,
  136.                                   realtype,
  137.                                   0,
  138.                                   0,
  139.                                   size );
  140.     if ( error != noErr )
  141.         return error;
  142.     
  143.     result= NewHandle(size);
  144.     if ( result==0 )
  145.         return mFulErr;
  146.     
  147.     templock lock(result);
  148.     return getparam( key,
  149.                           desired,
  150.                           realtype,
  151.                           *result,
  152.                           size,
  153.                           size );
  154.   }
  155.  
  156. OSErr aevent::getparam( AEKeyword key,
  157.                                 DescType desired,
  158.                                 AEDesc& result )
  159.   {
  160.     if (iswrong())
  161.         return whatiswrong();
  162.  
  163.     return AEGetParamDesc( this,
  164.                                   key,
  165.                                   desired,
  166.                                   &result );
  167.   }
  168.